package com.fb;

import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import java.io.File;
import android.os.Looper;

class LoadApkIcon extends Thread {
    FileBrowserPage fbp;
    File file;
    int index;
    int size;
    boolean needMap;
    LoadApkIcon(FileBrowserPage fbp,File file,int index,int size,boolean needMap){
        this.fbp=fbp;
        this.index=index;
        this.needMap=needMap;
        this.size=size;
        this.file=file;
    }
    @Override
    public void run(){
        super.run();
        PackageInfo pi=fbp.ma.pm.getPackageArchiveInfo(file.getAbsolutePath(),PackageManager.GET_ACTIVITIES);
        if(interrupted())return;
        Drawable d=pi.applicationInfo.loadIcon(fbp.ma.pm);
        final Bitmap b=Bitmap.createBitmap(size,size,Bitmap.Config.ARGB_8888);
        d.setBounds(0,0,size,size);
        d.draw(new Canvas(b));
        if(!interrupted()){
            fbp.ma.runOnUiThread(new Runnable(){
                    public void run(){
                        if(needMap){
                            if(fbp.willshowSorted!=null){
                                if(index<fbp.willshowSorted.length){
                                    int maped=fbp.willshowSorted[index];
                                    if(fbp.willshow[maped]==file){
                                        fbp.willshowIcons[maped]=b;
                                    }
                                }
                            }
                        }else{
                            if(index<fbp.willshowLen){
                                if(fbp.willshow[index]==file){
                                    fbp.willshowIcons[index]=b;
                                }
                            }
                        }
                        fbp.atIconLoaderEnd(LoadApkIcon.this,index);
                    }
                });
        }
    }
}
